/**
 * Copyright (C), 2020-2021 by colley.ma
 * File Name: RateLimitProviderExt.java
 * Encoding: UTF-8
 * Date: 2021年7月20日 下午1:19:39
 * History:
*/
package com.swak.frame.ratelimit.extension;

import org.springframework.beans.factory.annotation.Autowired;

import com.swak.frame.config.ConfigCenterAdapter;
import com.swak.frame.extension.annotation.Extension;
import com.swak.frame.ratelimit.config.LimitConfigVo;

@Extension(desc = "默认限流")
public class DefaultRateLimitExtProvider implements RateLimitExtPtProvider {
	
	@Autowired(required = false)
	private ConfigCenterAdapter configCenterAdapter;

	@Override
	public LimitConfigVo getConfig(String resource) {
		if (configCenterAdapter == null) {
			return null;
		}
		//qps：-1=使用注解的限流方式   0=不限流
		int qps = configCenterAdapter.getInt(resource, -1);
		// -1=没有配置
		if(qps<0) {
			return null;
		}
		return  new LimitConfigVo(resource, qps);
	}
}
